<?php /* $Id: index.php 6036 2010-10-02 04:10:36Z ajdonnison $ */

//$loginFromPage = 'index.php';
require_once 'base.php';

clearstatcache();

if (is_file(DP_BASE_DIR . '/includes/config.php')) {
	require_once DP_BASE_DIR . '/includes/config.php';

} else {
	echo ('<html><head><meta http-equiv="refresh" content="5; URL=' . DP_BASE_URL 
	      . '/install/index.php"></head><body>' 
	      . 'Fatal Error. You haven\'t created a config file yet.<br/>' 
	      . '<a href="./install/index.php">Click Here To Start Installation and Create One!</a>' 
	      . ' (forwarded in 5 sec.)</body></html>');
	exit();
}

if (!(isset($GLOBALS['OS_WIN']))) {
	$GLOBALS['OS_WIN'] = (mb_stristr(PHP_OS, 'WIN') !== false);
}

require_once (DP_BASE_DIR . '/classes/csscolor.class.php'); // Required before main_functions
require_once (DP_BASE_DIR . '/includes/main_functions.php');
require_once (DP_BASE_DIR . '/includes/db_adodb.php');
require_once (DP_BASE_DIR . '/includes/db_connect.php');

require_once (DP_BASE_DIR . '/classes/ui.class.php');
require_once (DP_BASE_DIR . '/classes/permissions.class.php');
require_once (DP_BASE_DIR . '/includes/session.php');

// don't output anything. Usefull for fileviewer.php, gantt.php, etc.
$suppressHeaders = dPgetParam($_GET, 'suppressHeaders', false);

// manage the session variable(s)
dPsessionStart(array('AppUI'));

// write the HTML headers

header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); //Date in the past
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); //always modified
header ('Cache-Control: no-cache, must-revalidate, no-store, post-check=0, pre-check=0'); //HTTP/1.1
header ('Pragma: no-cache');	// HTTP/1.0

// check if session has previously been initialised
if (!(isset($_SESSION['AppUI'])) || isset($_GET['logout'])) {
    if (isset($_GET['logout']) && isset($_SESSION['AppUI']->user_id)) {
        $AppUI =& $_SESSION['AppUI'];
        $AppUI->registerLogout($AppUI->user_id);
        addHistory('login', $AppUI->user_id, 'logout', 
		           ($AppUI->user_first_name . ' ' . $AppUI->user_last_name));
				if(isset($_GET['redirect'])){
					$rurl = dPgetCleanParam($_GET, 'redirect', '');
					Header("Location: $rurl");
				}
    }
	$_SESSION['AppUI'] = new CAppUI;
}
$AppUI =& $_SESSION['AppUI'];
$last_insert_id =$AppUI->last_insert_id;

// check if the user is trying to log in
// Note the change to REQUEST instead of POST.  This is so that we can
// support alternative authentication methods such as the PostNuke
// and HTTP auth methods now supported.
if (isset($_REQUEST['login'])) {
	$username = dPgetCleanParam($_GET, 'username', '');
	$password = dPgetCleanParam($_GET, 'password', '');

	if ($AppUI->doLogin()) {
		$ok = $AppUI->login($username, $password);

		if (!$ok) {
			$AppUI->setMsg('Login Failed');
		} else {
			//Register login in user_acces_log
			$AppUI->registerLogin();
			addHistory('login', $AppUI->user_id, 'login', 
		           ($AppUI->user_first_name . ' ' . $AppUI->user_last_name));			
		}
	}else{
		//
	}
	$AppUI->redirect('index.php');
}

ob_end_flush();
?>
